<?php
/**
 * polwebgis
 * 
 * This file is part of polwebgis.
 *
 * @copyright   Copyright (c) 2012 Dominik Janisch (http://www.joanneum.at)
 * @lastmodified    $LastChangedDate: 2012-03-07 09:15:12 +0000 (Wed, 07 Mar 2012) $
 * @revision    $Revision: 160 $ 
 */

class ContiguityRegion
{
    private $gid_;
    private $name_;
    private $cases_;
    private $standard_score_;
    private $arr_neighbours_ = array();
    private $neighbours_standard_score_ = 0;

    public function __construct($gid, $name, $cases, $standard_score)
    {
        $this->gid_ = $gid;
        $this->name_ = $name;
        $this->cases_ = $cases;
        $this->standarad_score_ = $standard_score;
    }
    
    public function __destruct(){}
    
    public function addNeighbour(ContiguityRegion $contiguity_region)
    {
        if(!array_key_exists($contiguity_region->getGid(), $this->arr_neighbours_))
        {
            $this->arr_neighbours_[$contiguity_region->getGid()] = $contiguity_region;
            $this->neighbours_standard_score_ += $contiguity_region->getStandardScore();
        }
    }
    
    public function getGid()
    {
        return $this->gid_;
    }
    
    public function getStandardScore()
    {
        return $this->standarad_score_;
    }
    
    public function getCases()
    {
        return $this->cases_;
    }
    
    public function getName()
    {
        return $this->name_;
    }
    
    public function calculateNeighbourScore()
    {
        if(count($this->arr_neighbours_) > 0)
            return $this->neighbours_standard_score_/count($this->arr_neighbours_);
        return 0;
    }
    
    public function calculateLocalMoran($m2)
    {
        return $this->standarad_score_/$m2 * $this->calculateNeighbourScore();
    }

}
?>
